# Copyright 1999-2004 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit eutils
S="${WORKDIR}"

DESCRIPTION="KDE application that creates video slideshows."
SRC_URI="http://csgib36.ifrance.com/Manslide/${P}.tar.gz"
HOMEPAGE="http://www.kde-apps.org/content/show.php/Manslide?content=72739"

LICENSE="GPL"
KEYWORDS="~x86"

IUSE="xine"
SLOT="0"

LANGS="fr en"

DEPEND="xine? ( >=media-video/xine-ui-0.99.4 )
	>=media-video/smilutils-0.3.0
	>=media-libs/netpbm-10.34
	media-video/mplayer
	>=media-sound/sox-14.0
	>=media-video/mjpegtools-1.9
	media-gfx/imagemagick
	>=x11-libs/qt-4.3"

RDEPEND="${DEPEND}"

src_unpack() {
        unpack ${A}

	cd ${S}/${P}
	LANGS=$(echo ${LINGUAS} | sed 's/linguas_//g' | sed 's/\([a-z][a-z]*\)_/\1 \1_/g' )
	einfo "Filtering languages ${LANGS}"
	# Find the langs (supported and wanted)
	kept_langs=""
	selected_langs=""
        for lang in ${LANGS}; do
	  if [ -f manslide_${lang}.ts ]; then
		selected_langs="${selected_langs} manslide_${lang}.ts"
		kept_langs="${kept_langs} ${lang}"
	  fi
        done
	if [ -z "${selected_langs}" ]; then
	  kept_langs="en"
	  selected_langs=manslide_en.ts
	fi
	einfo "Kept these languages: $kept_langs"
	# Replace the TRANSLATIONS list
	mv Manslide.pro Manslide.pro.bak
	cat Manslide.pro.bak | \
		tr '\n' '\\' | sed 's/\\\\\t/ /g' | sed 's/  */ /g' | tr '\\' '\n' | \
		sed "s/\(TRANSLATIONS = *\).*/\1${selected_langs}/g" >> Manslide.pro
	qmake
}

src_compile() {
        cd ${S}/${P}
        [ -d "$QTDIR/etc/settings" ] && addwrite "$QTDIR/etc/settings"
        addpredict "$QTDIR/etc/settings"
        qmake Manslide.pro || die
        emake || die
}

src_install() {
        if test ! -d ${D}/usr/bin ; then
                mkdir -p ${D}/usr/bin
        fi
	# It's custom to use lowercase letters on Unix/Linux
        cp ${P}/Manslide ${D}/usr/bin/manslide || die

        if test ! -d ${D}/usr/share/apps/manslide ; then
                mkdir -p ${D}/usr/share/manslide
        fi

        cp ${P}/manslide_*.qm ${D}/usr/share/manslide/ || die

        if test ! -d ${D}/usr/share/applnk/Multimedia ; then
                mkdir -p ${D}/usr/share/applnk/Multimedia
        fi

        echo "[Desktop Entry]
        Encoding=UTF-8
        Type=Application
        Exec=manslide
        Icon=manslide.png
        Comment=Simple slideshow creator
        Name=Manslide
        Terminal=false
        GenericName=Slideshow Creator" > ${D}/usr/share/applnk/Multimedia/manslide.desktop || die

        if test ! -d ${D}/usr/share/icons ; then
                mkdir -p ${D}/usr/share/icons
        fi

        cp  ${S}/${P}/Interface/renderer.png ${D}/usr/share/icons/manslide.png || die
}

pkg_postinst() {
        einfo "You must have QT4 and an OpenGL compatible video card."
	einfo "Be sure to add Load "glx" in module section of your /etc/X11/xorg.conf"
}

